package com.maochang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maochang.mapper.PsLineInfoMapper;
import com.maochang.mapper.PsPoleInfoMapper;
import com.maochang.pojo.PsLineInfo;
import com.maochang.pojo.PsPoleInfo;
import com.maochang.service.PsPoleInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("PsPoleInfoService")
public class PsPoleInfoServiceImpl extends ServiceImpl<PsPoleInfoMapper, PsPoleInfo> implements PsPoleInfoService {
    @Resource
    private PsPoleInfoMapper psPoleInfoMapper;

    @Resource
    private PsLineInfoMapper psLineInfoMapper;

    @Override
    public Page<PsPoleInfo> ChaPsPI(Integer lineId,Integer isStart, int current, int page) {
        Page<PsPoleInfo> psPIPage=new Page<>(current,page);
        QueryWrapper<PsPoleInfo> wrapper= Wrappers.query();
        /*查询是否是启用*/
        wrapper.eq(isStart!=null,"isStart",isStart);
        wrapper.eq(lineId!=null,"lineId",lineId);
        System.out.println("启用"+isStart);
        return psPoleInfoMapper.AllPsPI(psPIPage,wrapper);
    }

    @Override
    public void addPsPI(PsPoleInfo psPoleInfo) {
        psPoleInfoMapper.insert(psPoleInfo);
    }

    @Override
    public boolean ShanChu(Integer id) {
        QueryWrapper<PsPoleInfo> wrapper= Wrappers.query();
        wrapper.eq("id",id);
        int s=psPoleInfoMapper.delete(wrapper);
        boolean fAlg=false;
        if (s>0){
            fAlg=true;
        }
        return fAlg;
    }

    @Override
    public boolean PIUpdate(PsPoleInfo psPoleInfo) {
        PsPoleInfo psPoleInfo1=new PsPoleInfo();
        QueryWrapper<PsPoleInfo> wrapper=Wrappers.query();
        wrapper.eq("id",psPoleInfo.getId());
        int s=psPoleInfoMapper.update(psPoleInfo,wrapper);
        boolean fAlg=false;
        if (s>0){
            fAlg=true;
        }
        return fAlg;
    }

    @Override
    public List<PsLineInfo> ChaXia() {
        QueryWrapper<PsLineInfo> wrapper= Wrappers.query();
        wrapper.select("id","lineName");
        List<PsLineInfo>  psList =psLineInfoMapper.selectList(wrapper);
        return psList;
    }

    @Override
    public boolean QxZhuAngTai(Integer id, Integer isStart) {
        PsPoleInfo PsPI=new PsPoleInfo();
        PsPI.setIsStart(isStart);
        QueryWrapper<PsPoleInfo> wrapper= Wrappers.query();
        wrapper.eq("id",id);
        int i= psPoleInfoMapper.update(PsPI,wrapper);
        boolean PsILZ=false;
        if(i>0){
            PsILZ=true;
        }
        return PsILZ;
    }




}
